package by.qizer.supercamp.web;

import by.qizer.supercamp.domain.Guard;
import by.qizer.supercamp.domain.Owner;
import by.qizer.supercamp.service.GuardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Map;

/**
 * @author Pribytkoyski Alexey
 *         User: qizer
 *         Date: 08.04.12
 */
@Controller
public class GuardController {

    @Autowired
    private GuardService guardService;

    @RequestMapping(value = "/guardadd", method = RequestMethod.POST)
    public String addGuard(@ModelAttribute("guard") Guard guard, BindingResult result) {
        guardService.addGuard(guard);
        return "redirect:/guard";
    }

    @RequestMapping("/guard")
    public String listGuards(Map<String, Object> map) {
        map.put("guard", new Guard());
        map.put("guardList", guardService.listGuards());
        return "guard";
    }

    @RequestMapping("/guarddel/{guardId}")
    public String deleteGuard(@PathVariable("guardId") Integer guardId) {
        guardService.removeGuard(guardId);
        return "redirect:/guard";
    }
}
